package book;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockTest implements Runnable{

	Lock lock = new ReentrantLock();

	@Override
	public void run() {

		lock.lock();
		try {
			for (int i = 0; i < 5; i++) {

				System.out.println(Thread.currentThread().getName() + "：" + i);
			} 
		} finally {
			lock.unlock();
		}
	}
	
	public static void main(String[] args) {
		
		ReentrantLockTest lockTask = new ReentrantLockTest();
		Thread t = new Thread(lockTask);
		Thread t2 = new Thread(lockTask);
		Thread t3 = new Thread(lockTask);
		
		t.start();
		t2.start();
		t3.start();
	}
}
